package com.yd.app.service.mobile.noticeService;

import com.yd.app.mapper.NoticeMapper;
import com.yd.app.service.common.BaseService;
import com.yd.domain.business.Notice;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.NoticeParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zy
 * @create 2018-03-09 14:05
 * @desc 公告service
 **/
@Service
public class MNoticeService extends BaseService {
    @Autowired
    private NoticeMapper noticeMapper;

    /**
     * @Author: zy
     * @Desc: 根据id查询
     * @Date:  2018/3/9
     * @Param
     */
    public Notice findById(String id){
        Notice notice=new Notice();
        notice=noticeMapper.findById(id);
        return notice;
    }

    /**
     * @Author: zy
     * @Desc: 分页查询数据列表
     * @Date:  2018/3/9
     * @Param
     */
    public PageModel getNoticeList(NoticeParam noticeParam, int pageIndex, int pageSize){
        PageModel pm=new PageModel();
        List<Notice> list=new ArrayList<>();
        list=noticeMapper.searchNoticeList(noticeParam,getStartRow(pageIndex,pageSize),pageSize);
        int count=0;
        if(pageIndex==1){
            //查询总条数
            count=noticeMapper.searchNoticeCount(noticeParam);
            pm.setCount(count);
        }
        pm.setList(list);
        return pm;
    }

    //获取通知公告
    public Notice getNotice() {
        Notice n=noticeMapper.getNotice();
        return n;
    }
}
